package com.example.pucha_xian.common;

import com.example.pucha_xian.Class.CPoint;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class Convert {


    public static Map<String, String> object2Map (CPoint cPoint) throws IllegalAccessException {
        Map<String, String> map = new HashMap<>();
        Field[] fields = cPoint.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object value = field.get(cPoint);
            if (value != null){
                if(value instanceof String){
                    map.put(fieldName, (String) value);
                }else {
                    map.put(fieldName, String.valueOf(value));
                }
            }
        }
        return map;
    }

}
